<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseLink.class.php';

Class Link {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjLink = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objLink = new BaseLink();
			$objLink->setLinkId( ( true == isset( $row["link_id"] ) ) ? $row["link_id"] : 'NULL' );
			$objLink->setMid( ( true == isset( $row["mid"] ) ) ? $row["mid"] : 'NULL' );
			$objLink->setUserId( ( true == isset( $row["user_id"] ) ) ? $row["user_id"] : 'NULL' );
			$objLink->setLevelId( ( true == isset( $row["level_id"] ) ) ? $row["level_id"] : 'NULL' );
			$objLink->setDummy( ( true == isset( $row["dummy"] ) ) ? $row["dummy"] : 'NULL' );
			array_push( $arrobjLink, $objLink );
		}
		return $arrobjLink;
	}
	public function fetchAllLink() {
		$result = $this->connection->RunQuery("SELECT * FROM LINK");
		$arrobjLink = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objLink = new BaseLink();
			$objLink->setLinkId( ( true == isset( $row["link_id"] ) ) ? $row["link_id"] : 'NULL' );
			$objLink->setMid( ( true == isset( $row["mid"] ) ) ? $row["mid"] : 'NULL' );
			$objLink->setUserId( ( true == isset( $row["user_id"] ) ) ? $row["user_id"] : 'NULL' );
			$objLink->setLevelId( ( true == isset( $row["level_id"] ) ) ? $row["level_id"] : 'NULL' );
			$objLink->setDummy( ( true == isset( $row["dummy"] ) ) ? $row["dummy"] : 'NULL' );
			array_push( $arrobjLink, $objLink);
		}
		return $arrobjLink;
	}
	public function fetchAllLinkByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM LINK WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjLink = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objLink->setLinkId( ( true == isset( $row["link_id"] ) ) ? $row["link_id"] : 'NULL' );
			$objLink->setMid( ( true == isset( $row["mid"] ) ) ? $row["mid"] : 'NULL' );
			$objLink->setUserId( ( true == isset( $row["user_id"] ) ) ? $row["user_id"] : 'NULL' );
			$objLink->setLevelId( ( true == isset( $row["level_id"] ) ) ? $row["level_id"] : 'NULL' );
			$objLink->setDummy( ( true == isset( $row["dummy"] ) ) ? $row["dummy"] : 'NULL' );
			array_push( $arrobjLink, $objLink );
		}
		return $arrobjLink;
	}

	public function fetchLinkById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM LINK WHERE id = " . $intId );
			$objLink = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objLink = new BaseLink();
			$objLink->setLinkId( ( true == isset( $row["link_id"] ) ) ? $row["link_id"] : 'NULL' );
			$objLink->setMid( ( true == isset( $row["mid"] ) ) ? $row["mid"] : 'NULL' );
			$objLink->setUserId( ( true == isset( $row["user_id"] ) ) ? $row["user_id"] : 'NULL' );
			$objLink->setLevelId( ( true == isset( $row["level_id"] ) ) ? $row["level_id"] : 'NULL' );
			$objLink->setDummy( ( true == isset( $row["dummy"] ) ) ? $row["dummy"] : 'NULL' );
		}
		return $objLink;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT link_id from link order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["link_id"];
				$i++;
			}
	return $keys;
	}

	public function endLink(){
		$this->connection->CloseMysql();
	}

}